// 解构: 可以从数组或对象中提取值并赋给变量

// 解构数组
let [x, y] = [1, 2]
console.log("x:", x, "y:", y)
// x: 1 y: 2

let [, , c] = [10, 20, 30]
console.log("c:", c)

// 扩展运算符
let [a, ...b] = [1, 2, 3, 4, 5]
console.log("a:", a, "b:", b)
// a: 1 b: [ 2, 3, 4, 5 ]

// 默认值
let [x1, y1 = 200] = [100]
console.log("x1:", x1, "y1:", y1)
// x1: 100 y1: 200

// 两数交换
let x2 = 1
let y2 = 2;// 不加分号会报错

[x2, y2] = [y2, x2]
console.log("x2:", x2, "y2:", y2)

// 对象解构
let myself = {
    name: 'Dcsgo',
    gender: '男',
    web: 'dcsgo.com.cn'
}

let { name } = myself
console.log("myself name:", name)
// myself name: Dcsgo

// 重命名
let { name: myName } = myself
console.log("myName:", myName)
// myName: Dcsgo